package com.sc.nft.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.sc.nft.dao.DaoIdentityDao;
import com.sc.nft.dao.UserCollectionDao;
import com.sc.nft.dao.UserCreatorInfoDao;
import com.sc.nft.entity.DaoIdentity;
import com.sc.nft.entity.UserCreatorInfo;
import com.sc.nft.entity.UserInfo;
import com.sc.nft.entity.vo.CatenaIdsGroupByCatenaVO;
import com.sc.nft.service.CatenaCertificateService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RequiredArgsConstructor
@Service
public class CatenaCertificateServiceImpl implements CatenaCertificateService {


    private final UserCreatorInfoDao userCreatorInfoDao;

    private final DaoIdentityDao daoIdentityDao;

    private final UserCollectionDao userCollectionDao;



    @Override
    public Boolean userIsExistGroup(UserInfo userInfo ,Long id) {
        UserCreatorInfo byId = userCreatorInfoDao.getById(id);
        if (byId.getUserId() != null && byId.getUserId().equals(userInfo.getId())) {
            return Boolean.TRUE;
        }
        List<DaoIdentity> daoIdentityList = daoIdentityDao.getByDaoId(id);
        if(CollUtil.isEmpty(daoIdentityList)){
            return Boolean.FALSE;
        }
        List<Long> collectionList = daoIdentityList.stream().map(DaoIdentity::getCollectionId).collect(Collectors.toList());
        return userCollectionDao.userHasCollections(userInfo.getId(),collectionList);
    }

    @Override
    public List<CatenaIdsGroupByCatenaVO> selectByCatenaIdsGroupByCatena(List<Long> ids) {
        return daoIdentityDao.selectByCatenaIdsGroupByCatena(ids);
    }



}
